home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-15 | 12.0 KB | 499 lines | [TEXT/MPS ] |
- Libraries "MemoryMonitor.vulib";
-
- #######################################################################################
- # MemoryMonitor Example Script
- #
- # • What's this script do?
- # This script demonstrates the Memory Monitor V.U. external tool.
- #
- # • Where will Memory Monitor run?
- # If a target is assigned to the user within the V.U. document,
- # then the script will expect Memory Monitor to be on the Target.
- #
- # If the V.U. document has no target assigned,
- # then the script will expect Memory Monitor to be on the Host.
- #
- #######################################################################################
- Script MemoryMonitorExample()
- Begin
- ### These flags control the verbosity & beauty of printed output.
- ### All flags true yields more and formatted output.
- global TraceToolCalls := true;
- global ReportSuccess := true;
- global FormattedOutput := true;
-
- ### Initialize Memory Monitor either on the Host, or the Target
- OnTheTarget := match[ target ];
- x := InitMemoryMonitor( OnTheTarget );
-
- ### Demonstrate each available service
- x := GetProcessInfo( 'Finder' );
-
- ### Quit Memory Monitor
- x := QuitMemoryMonitor();
-
- end;
-
- #######################################################################################
- Task CallEachService()
- Begin
-
- ### Call each Memory Monitor service
- ### Exit with error code, if an error is encountered
-
- x := Demo_GetToolVersion();
-
- x := Demo_GetToolServices();
-
- x := Demo_ServiceSupported( 'GetToolVersion' );
-
- x := Demo_GetProcessInfo( 'Memory Monitor' );
-
- x := Demo_GetAllProcesses();
-
- x := Demo_GetZoneMap( 'MultiFinderZone' );
-
- x := Demo_GetZoneTotals( 'SystemZone' );
-
- x := Demo_CheckZone( 'Memory Monitor' );
-
- x := Demo_GetAboutThisMacintosh();
-
- x := Demo_ReadBytes();
-
- x := Demo_MacsbugCmd( "HT" );
-
- end;
-
- #######################################################################################
- Task Demo_GetToolVersion()
- Begin
-
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— GetToolVersion";
- end;
-
- x := MemoryMonitor( 'GetToolVersion' );
- if x[1] = 0
- begin
- if global ReportSuccess
- begin
- Println x[2];
- end;
- end;
- else
- begin
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
-
- #######################################################################################
- Task Demo_GetToolServices()
- Begin
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— GetToolServices";
- end;
-
- x := MemoryMonitor( 'GetToolServices' );
- if x[1] = 0
- begin
- if global ReportSuccess
- Println x[2];
- end;
- else
- begin
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
-
- #######################################################################################
- Task Demo_ServiceSupported( SrvcName )
- Begin
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— ServiceSupported";
- end;
-
- x := MemoryMonitor( 'ServiceSupported', SrvcName );
- if x[1] = 0
- begin
- if global ReportSuccess
- Println x[2];
- end;
- else
- begin
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
-
- #######################################################################################
- Task Demo_GetAllProcesses()
- Begin
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— GetAllProcesses";
- end;
-
- x := GetAllProcesses();
- if x[1] = 0
- begin
- if global ReportSuccess
- begin
- if global FormattedOutput
- PrintProcessMap( x[2] );
- else
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
- else
- begin
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
-
- #######################################################################################
- Task Demo_GetProcessInfo( ProcessName )
- Begin
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— GetProcessInfo";
- end;
-
- x := GetProcessInfo( ProcessName );
- if x[1] = 0
- begin
- if global ReportSuccess
- begin
- if global FormattedOutput
- PrintProcessInfo( x[2] );
- else
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
- else
- begin
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
-
- #######################################################################################
- Task Demo_GetZoneMap( ZoneSelector )
- Begin
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— GetZoneMap : {ZoneSelector}";
- end;
-
- x := GetZoneMap( ZoneSelector );
- if x[1] = 0
- begin
- if global ReportSuccess
- begin
- if global FormattedOutput
- PrintZoneMap( x[2], ZoneSelector );
- else
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
- else
- begin
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- return x[1];
- end;
-
- #######################################################################################
- Task Demo_GetZoneTotals( ZoneSelector )
- Begin
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— GetZoneTotals : {ZoneSelector}";
- end;
-
- x := GetZoneTotals( ZoneSelector );
- if x[1] = 0
- begin
- if global ReportSuccess
- begin
- if global FormattedOutput
- PrintZoneTotals( x[2], ZoneSelector );
- else
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
- else
- begin
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- return x[1];
- end;
-
- #######################################################################################
- Task Demo_CheckZone( ZoneSelector )
- Begin
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— CheckZone : {ZoneSelector}";
- end;
-
- x := CheckZone( ZoneSelector );
- if x[1] = 0 and TypeOf( x[2] ) = 'symbol'
- begin
- if global ReportSuccess
- begin
- if global FormattedOutput
- Println "Zone Ok - ", ZoneSelector;
- else
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
- else
- begin
- if global FormattedOutput
- Println "Zone Corrupt - ", ZoneSelector;
- else
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- return x[1];
- end;
-
- #######################################################################################
- Task Demo_GetAboutThisMacintosh()
- Begin
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— GetAboutThisMacintosh";
- end;
-
- x := GetAboutThisMacintosh();
- if x[1] = 0
- begin
- if global ReportSuccess
- begin
- if global FormattedOutput
- PrintAboutThisMacintosh( x[2] );
- else
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
- else
- begin
- Println "DoGetAboutThisMacintosh";
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
-
- #######################################################################################
- Task Demo_ReadBytes()
- Begin
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— ReadBytes";
- end;
-
- ### Read the low global 'CurApName',
- ### which contains the current application name
- x := ReadBytes( { 0, 2320 }, 32 );
- if x[1] = 0
- begin
- if global ReportSuccess
- begin
- if TypeOf( x[2] ) = 'list'
- begin
- ### Assemble the bytes into a string and then print
- s := "";
- for i := 2 to x[2][1] + 1
- s := s + CodeToCharacter( x[2][i] );
- Println "Application Name ( CurApName ) = '", s, "'";
- end;
- end;
- end;
- else
- begin
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
-
- #######################################################################################
- Task Demo_MacsbugCmd( CmdLine )
- Begin
- if global TraceToolCalls
- begin
- Println;
- Println "——————————————————————————————————————— MacsbugCmd";
- end;
-
- x := MacsbugCmd( CmdLine );
- if x[1] = 0
- begin
- if global ReportSuccess
- begin
- Println "MacsbugCmd : '", CmdLine, "'";
- Println "Result : ", x[2];
- end;
- end;
- else
- begin
- Println "MacsbugCmd : '", CmdLine, "' Result : ", x[2];
- Println x[1], " ", x[2], " ", x[3], " ", x[4];
- end;
- end;
-
- #######################################################################################
- Task PrintProcessMap( pMap )
- Begin
- for each P in pMap
- begin
- PrintProcessInfo( P );
- end;
- end;
-
- #######################################################################################
- Task PrintProcessInfo( P )
- Begin
- Println;
- Println "Name - ", P[1];
- Println "Type - ", P[2];
- Println "Signature - ", P[3];
- Println "Location - ", RightJustify( P[4], 12 );
- Println "Size - ", RightJustify( P[5], 12 );
- Println "Free Memory - ", RightJustify( P[6], 12 );
- Println "Path Name - ", P[7];
- end;
-
- #######################################################################################
- Task PrintZoneMap( pMap, pZoneID, Label := "", Indent := "" )
- Begin
- if Label = ""
- begin
- Println;
- Println "Zone First Last Size in";
- Println "Specifier Address Address Bytes";
- Println "--------- ------- ------- -------";
-
- if TypeOf( pZoneID ) = 'list'
- For each i in pZoneID
- begin
- if TypeOf( i ) = 'integer'
- begin
- i := NumToStr( i );
- end;
-
- if Card Label > 0
- Label := Label + ", " + i;
- else
- Label := i;
- end;
- else
- begin
- Label := pZoneID;
- end;
- end;
-
- Println LeftJustify( Label, 20 ),
- Indent,
- RightJustify( pMap[1], 14 ),
- RightJustify( pMap[2], 14 ),
- RightJustify( pMap[3], 14 );
-
- if TypeOf( pMap[4] ) = 'list'
- begin
- Index := 1;
- for each Z in pMap[4]
- begin
- PrintZoneMap( Z, pZoneID, Label + "," + RightJustify( NumToStr( Index ), 2), Indent + " " );
- Index := Index + 1;
- end;
- end;
- end;
-
- #######################################################################################
- Task PrintZoneTotals( T, ZoneID := "" )
- Begin
- Println "Zone Totals for : ", ZoneID;
- Println " Blocks Bytes";
- Println " ------ -----";
- Println "Free - ", RightJustify( NumToStr( T[1][1] ), 7 ), ", ", RightJustify( T[1][2], 11 );
- Println "NonRelocatable - ", RightJustify( NumToStr( T[2][1] ), 7 ), ", ", RightJustify( T[2][2], 11 );
- Println "Relocatable - ", RightJustify( NumToStr( T[3][1] ), 7 ), ", ", RightJustify( T[3][2], 11 );
- Println " Locked - ", RightJustify( NumToStr( T[4][1] ), 7 ), ", ", RightJustify( T[4][2], 11 );
- Println " Purgable & Unlocked - ", RightJustify( NumToStr( T[5][1] ), 7 ), ", ", RightJustify( T[5][2], 11 );
- Println "Total - ", RightJustify( NumToStr( T[6][1] ), 7 ), ", ", RightJustify( T[6][2], 11 );
- end;
-
- #######################################################################################
- Task PrintAboutThisMacintosh( pAbout )
- Begin
- Println "Built-in Memory - ", RightJustify( pAbout[1], 10 ), "K";
- Println "Total Memory - ", RightJustify( pAbout[2], 10 ), "K";
- Println "Largest Unused block - ", RightJustify( pAbout[3], 10 ), "K";
- if (not IsUndefined( pAbout[4] )) and Card pAbout[4] > 1
- begin
- For each appInfo in pAbout[4]
- begin
- Println " ", LeftJustify( appInfo[1], 32 ), " - ", RightJustify( appInfo[2], 10 ), "K";
- end;
- end;
- end;
-
- #######################################################################################
- Task RightJustify( TStr, FieldWidth )
- begin
- PadStr := "";
- L := Card TStr;
- if L < FieldWidth
- begin
- PadLength := FieldWidth - L;
- L := (PadLength - Card PadStr) / 8;
- for i := 1 to L
- PadStr := PadStr + " ";
-
- If PadLength - Card PadStr >= 4
- PadStr := PadStr + " ";
-
- If PadLength - Card PadStr >= 2
- PadStr := PadStr + " ";
-
- If PadLength - Card PadStr >= 1
- PadStr := PadStr + " ";
- end;
- return PadStr + TStr;
- end;
-
- #######################################################################################
- Task LeftJustify( TStr, FieldWidth )
- begin
- PadStr := "";
- L := Card TStr;
- if L < FieldWidth
- begin
- PadLength := FieldWidth - L;
- L := (PadLength - Card PadStr) / 8;
- for i := 1 to L
- PadStr := PadStr + " ";
-
- If PadLength - Card PadStr >= 4
- PadStr := PadStr + " ";
-
- If PadLength - Card PadStr >= 2
- PadStr := PadStr + " ";
-
- If PadLength - Card PadStr >= 1
- PadStr := PadStr + " ";
- end;
- return TStr + PadStr;
- end;
-
-